/**
 * 
 */
package com.atung.dao;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.atung.model.BusCarRide;
import com.atung.model.RefundDO;

/**
 * 
 * @author lc <br>
 * 2020年11月23日 下午4:37:49
 */
@Mapper
public interface BusOrederCarLCDAO {


    /**
     * 根据订单id和openId获取订单信息
     */
    @Select("SELECT zf.id,zf.payment_id,zf.open_id,ls.rout_publish_id,zf.order_state,order_status,ls.order_payable_money,allocation_id FROM bus_order_car zf "
            + "LEFT JOIN bus_school_bus_payment ls ON ls.id = zf.payment_id  "
            + "where zf.id =#{num} and zf.open_id =#{openId}")
    RefundDO getById(@Param("num")Long num,@Param("openId") String openId);
    
    @Select("SELECT expiration_date FROM bus_rout_publish WHERE id = #{id}")
    LocalDateTime getRouteExpirationTime(Long id);
    
    /**
     * 修改流水单状态为退款中
     */
    @Update("UPDATE bus_school_bus_payment SET order_status = 206 ,modification_time=#{modificationTime}   where id = #{id} ")
    Boolean updatePublishRefund(@Param("id")Long id,@Param("modificationTime")LocalDateTime date);
    /**
     * 修改支付订单状态为退款中
     */
    @Update("UPDATE bus_order_car SET order_state = 304,modification_time=#{modificationTime} where id = #{id} ")
    Boolean updateOrderRefund(@Param("id")Long id,@Param("modificationTime")LocalDateTime date);
    
    /**
     * 修改车辆分配人员表状态为删除
     */
    @Update("UPDATE bus_car_ride SET is_delect = 1,modification_time=#{modificationTime} WHERE order_id = #{orderId} ")
    Integer updateDeletByOrderId(@Param("orderId")Long orderId,@Param("modificationTime")LocalDateTime date);
    
    /**
     * 查询车辆分配人员表
     */
    @Select("SELECT id,allocation_id FROM bus_car_ride WHERE order_id = #{orderId}")
    List<BusCarRide> getListRideByOrderId(Long orderId);
    
    /**
     * 修改车辆分配表人数
     */
    @Update("UPDATE bus_car_allocation SET current_nember = #{currentNember},modification_time=#{modificationTime} WHERE id = #{id}")
    Integer updateNemberById(@Param("id")Long id,@Param("currentNember")String currentNember,@Param("modificationTime")LocalDateTime date);
    
    /**
     * 根据id查询分配人数
     */
    @Select("SELECT current_nember FROM bus_car_allocation WHERE id = #{id}")
    String getNemberById(Long id);
    
    /**
     * 查询是否安排车辆
     */
    @Select("SELECT car_id FROM bus_car_allocation WHERE id = #{id}")
    Long getCarIdById(Long id);
}
